﻿var widgets = {};
(function($) {
    $.extend(true, widgets, {
        buildImportStockTable: function(stock, detaillist, house) {
            var html = [];

            html.push('<table class="infotable"><tr>');
            html.push('<td><label>仓库：</label>' + house.Name + '</td>');
            html.push('<td><label>编号：</label>' + stock.SerialNumber + '</td>');
            html.push('<td><label>入库日期：</label>' + stock.IncomingDate + '</td>');
            html.push('<td><label>供货商：</label>' + SUPPLIERS[stock.Tag].Name + '</td>');
            html.push('</tr></table>');
            html.push('<table class="datatable">');
            html.push('<tr>')
            html.push('<th><label>编号</label></th>')
            html.push('<th><label>产品名称</label></th>')
            html.push('<th><label>单位</label></th>')
            html.push('<th><label>规格</label></th>')
            html.push('<th><label>数量</label></th>')
            html.push('<th><label>单价</label></th>')
            html.push('<th><label>金额</label></th>')
            html.push('<th><label>备注</label></th>')
            html.push('</tr>')
            $.each(detaillist, function() {
                var s = PRODUCTSPECIFICATIONS[this.ProductSpecificationID];
                var p = PRODUCTS[s.ProductID];
                html.push('<tr>');
                html.push('<td>' + this.SerialNumber + '</td>');
                html.push('<td>' + [p.Name, p.Grade, p.Model].join(" ") + '</td>');
                html.push('<td>' + s.Unit + '</td>');
                html.push('<td>' + s.Specification + '</td>');
                html.push('<td>' + this.Count + '</td>');
                html.push('<td style="text-align:right;">' + this.Price + '</td>');
                html.push('<td style="text-align:right;">' + this.Amount + '</td>');
                html.push('<td>' + this.Comments + '</td>');
                html.push('</tr>');
            });
            html.push('<tr>');
            html.push('<td>合计</td>');
            html.push('<td colspan="5"></td>');
            html.push('<td style="text-align:right;">￥' + stock.Amount + '</td>');
            html.push('<td>' + stock.Comments + '</td>');
            html.push('</tr>');
            html.push('</table>');
            html.push('<table class="infotable"><tr>');
            html.push('<td><label>记账 ：</label>' + stock.BookKeeper + '</td>');
            html.push('<td><label>库管：</label>' + stock.WarehouseKeeper + '</td>');
            html.push('<td><label>验收：</label>' + stock.Accepter + '</td>');
            html.push('<td><label>制票：</label>' + stock.Drawer + '</td>');
            html.push('</tr></table>');
            return html.join('');
        },
        buildMoveStockTable: function(stock, detaillist, fromHouse,toHouse) {
            var html = [];

            html.push('<table class="infotable"><tr>');
            html.push('<td><label>移出仓库：</label>' + fromHouse.Name + '</td>');
            html.push('<td><label>移入仓库：</label>' + toHouse.Name + '</td>');
            html.push('<td><label>编号：</label>' + stock.SerialNumber + '</td>');
            html.push('<td><label>移库日期：</label>' + stock.MovingDate + '</td>');
            html.push('</tr></table>');
            html.push('<table class="datatable">');
            html.push('<tr>')
            html.push('<th><label>编号</label></th>')
            html.push('<th><label>产品名称</label></th>')
            html.push('<th><label>单位</label></th>')
            html.push('<th><label>规格</label></th>')
            html.push('<th><label>数量</label></th>')
            html.push('<th><label>备注</label></th>')
            html.push('</tr>')
            $.each(detaillist, function() {
                var s = PRODUCTSPECIFICATIONS[this.ProductSpecificationID];
                var p = PRODUCTS[s.ProductID];
                html.push('<tr>');
                html.push('<td>' + this.SerailNumber + '</td>');
                html.push('<td>' + [p.Name, p.Grade, p.Model].join(" ") + '</td>');
                html.push('<td>' + s.Unit + '</td>');
                html.push('<td>' + s.Specification + '</td>');
                html.push('<td>' + this.Count + '</td>');
                html.push('<td>' + this.Comments + '</td>');
                html.push('</tr>');
            });
            html.push('</table>');
            return html.join('');
        }
    });
})(jQuery);